package com.itheima.web.controller.pms;

import com.itheima.dto.pms.ProductCreateDto;
import com.itheima.result.PageResult;
import com.itheima.result.ResultData;
import com.itheima.service.pms.PmsProductService;
import com.itheima.vo.pms.Product;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("product")
@Slf4j
public class PmsProductController {

    @DubboReference
    private PmsProductService pmsProductService;

    /**
     * 新增商品
     * @param
     * @return
     */
    @PostMapping("create")
    public ResultData addCreate(@RequestBody ProductCreateDto productCreateDto) {
        pmsProductService.addCreate(productCreateDto);
        return ResultData.ok("操作成功","");
    }

    /**
     * 查询商品
     * @param brandId
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @param productCategoryId
     * @param productSn
     * @param publishStatus
     * @param verifyStatus
     * @return
     */
    @GetMapping("list")
    public ResultData list(Long brandId , String keyword , Long pageNum , Long pageSize , Long productCategoryId , String productSn , Integer publishStatus , Integer verifyStatus) {
        PageResult pageResult = pmsProductService.productList(brandId , keyword , pageNum , pageSize , productCategoryId , productSn , publishStatus , verifyStatus);
        return ResultData.ok("操作成功" , pageResult);
    }

    /**
     * 根据商品名称或货号模糊查询
     * @param keyword
     * @return
     */
    @GetMapping("simpleList")
    public ResultData simpleList(String keyword) {
        List<Product> product = pmsProductService.keyword(keyword);
        return ResultData.ok("" , product);
    }

    /**
     * 批量修改删除状态
     * @param deleteStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/deleteStatus")
    public ResultData updateDeleteStatus(@RequestParam Integer deleteStatus , @RequestParam List<Integer> ids){
        pmsProductService.updateDeleteStatus(deleteStatus , ids);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 批量设为新品
     * @param newStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/newStatus")
    public ResultData updateNewStatus(@RequestParam Integer newStatus , @RequestParam List<Integer> ids) {
        pmsProductService.updateNewStatus(newStatus , ids);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 批量上下架商品
     * @param publishStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/publishStatus")
    public ResultData updatePublishStatus(@RequestParam Integer publishStatus , @RequestParam List<Integer> ids) {
        pmsProductService.updatePublishStatus(publishStatus , ids);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 批量推荐商品
     * @param recommendStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public ResultData updateRecommendStatus(@RequestParam Integer recommendStatus , @RequestParam List<Integer> ids) {
        pmsProductService.updateRecommendStatus(recommendStatus , ids);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 批量修改审核状态
     * @param verifyStatus
     * @param detail
     * @param ids
     * @return
     */
    @PostMapping("/update/verifyStatus")
    public ResultData updateVerifyStatus(@RequestParam Integer verifyStatus , @RequestParam String detail , @RequestParam List<Long> ids) {
        pmsProductService.updateVerifyStatus(verifyStatus , detail , ids);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 根据商品id获取商品编辑信息
     * @param id
     * @return
     */
    @GetMapping("/updateInfo/{id}")
    public ResultData updateInfo(@PathVariable Long id) {
        return ResultData.ok("操作成功" , pmsProductService.updateInfo(id));
    }

    /**
     * 更新商品
     * @param id
     * @param productCreateDto
     * @return
     */
    @PostMapping("update/{id}")
    public ResultData updateProduct(@PathVariable Long id , @RequestBody ProductCreateDto productCreateDto) {
        pmsProductService.updateProduct(id , productCreateDto);
        return ResultData.ok("操作成功" , "");
    }
}
